﻿# -*- coding: utf-8 -*-
'''
Created on 2012-12-2

@author: yangxiao
'''
import getopt
import sys
import os
from dtBili import *
def __main(argv):
    print(len(argv))
    print(argv)
    if not os.path.exists('download'): os.makedirs('download')
    ls=argv[1:]
    opts,ls=getopt.getopt(ls,'hd', ['help','down'])
    for opt,arg in opts:
        if opt in ['-h','--help']:
            print u'-d [type] [url] 下载指定内容'
            print u'   type=bin,html,subtitle 分别为二进制文件,html,弹幕文件'
            return      
        elif opt in ['-d','--down'] and len(ls)==2:
            if ls[0]=='bin':
                downloadFile(ls[1])
            elif ls[0]=='html':
                s=getHtml(ls[1])
                name=getFileNameFromUrl(ls[1])
                saveTxt(s, './download/'+name)
            elif ls[0]=='subtitle':
                s,nurl=getSubtitle(ls[1])
                name=getFileNameFromUrl(nurl)
                saveTxt(s,'./download/'+name)
        else: print u'参数错误'

if __name__ =='__main__':
    #__main(sys.argv)
    __main([ ' ','-d','bin','http://219.239.26.19/download/27275256/34739127/3/iso/43/67/1335483726379_579/ubuntu-12.04-alternate-i386.iso'])